/***************************************************************************
 创建者：       hualei
 开始时间：    2018.09.10
 copyright:(C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************/
#include "modbusstartinstructiondelegate.h"
#include <QDebug>

ModbusStartInstructionDelegate::ModbusStartInstructionDelegate(QWidget *parent)
    : QObject(parent)
{
}

void ModbusStartInstructionDelegate::initView()
{
    modbusStartInstructionView->modbusSpecType = E_MODBUS_SPEC_TYPE_INTERNET_MASTER;
    modbusStartInstructionView->modbusID = 1;
    modbusStartInstructionView->noteStr = "(no noteStr!)";
    modbusStartInstructionView->JMP_LB_Velue = 1;

}

void ModbusStartInstructionDelegate::finishEditInstructionSlot()
{
    QString instructionStr = tr("MODBUS_START ,");

    qDebug() << " ModbusStartInstructionDelegate::finishEditInstructionSlot() ==== NoteStr:" << modbusStartInstructionView->noteStr;

    instructionStr += QString("%1").arg(modbusStartInstructionView->modbusID);

    QString modbusType;
    QString modbusMode;

    if(modbusStartInstructionView->modbusSpecType == E_MODBUS_SPEC_TYPE_INTERNET_MASTER)
    {
        modbusType = tr(",INTERNET ");
        modbusMode = tr(",MASTER, ");
    }
    else if(modbusStartInstructionView->modbusSpecType == E_MODBUS_SPEC_TYPE_INTERNET_SLAVE)
    {
        modbusType = tr(",INTERNET ");
        modbusMode = tr(",SLAVE, ");
    }
    else if(modbusStartInstructionView->modbusSpecType == E_MODBUS_SPEC_TYPE_RS485_MASTER)
    {
        modbusType = tr(",RS485 ");
        modbusMode = tr(",MASTER, ");
    }
    else if(modbusStartInstructionView->modbusSpecType == E_MODBUS_SPEC_TYPE_RS485_SLAVE)
    {
        modbusType = tr(",RS485 ");
        modbusMode = tr(",SLAVE, ");
    }

    instructionStr += modbusType + modbusMode;

    instructionStr += tr("JMP LB[") + QString("%1").arg(modbusStartInstructionView->JMP_LB_Velue) + "]  //";

    instructionStr += modbusStartInstructionView->noteStr;

    modbusStartInstructionView->instruction = instructionStr;
}

void ModbusStartInstructionDelegate::cleanNoteSlot()
{
    modbusStartInstructionView->noteStr.clear();
    qDebug() << "ModbusStartInstructionView::cleanNote";
}



